package com.xin.demo.springboot_xin_demo4.config;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.util.Properties;

@Configuration
public class PlaceHolderConfig {
    @Bean
    public PageHelper pageHelper(){
        PageHelper pageHelper=new PageHelper();
        //属性设置
        Properties properties = new Properties();
        properties.setProperty("offsetAsPageNum", "true");
        properties.setProperty("rowBoundsWithCount", "true");
        properties.setProperty("reasonable", "true");
        properties.setProperty("dialect","mysql");
        pageHelper.setProperties(properties);
        return pageHelper;
    }
    @Bean(name = "dataSource")
    @Qualifier(value = "dataSource")
     public DataSource dataSource()
    {
        //从zookeeper获取数据库连接数据；
        DynamicConfigDatasource datasource = DynamicConfigDatasource.create("127.0.0.1");
        //datasource.getConnection().
        return datasource;
    }
}
